<? /*
**************************************************
*	Crisses Mailinglist	       					 *
**************************************************
|                                                |
|   See install.txt for copyright & license info.|
-------------------------------------------------
*/ ?><?
session_start();
#error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);

include('config.php');
include("FCKeditor/fckeditor.php") ;
require('Swift/Swift.php');
require('Swift/plugins/Swift_Anti_Flood_Plugin.php');
require('Swift/Swift/Swift_SMTP_Connection.php');
$language = "languages/".$language.".php";
include($language);
include('functions.php');
include_once "version.php";


$conn = mysql_connect($address, $username, $sql_password);


$url = explode('&',$_SERVER['QUERY_STRING']);
$url = explode('=',$url[0]);

mysql_select_db($db);

if((!isset($_SESSION['password']))&&(!isset($_POST['password']))){

	$display_block = "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">
	   <p>".$l_password.": <input type=\"password\" name=\"password\" size=\"20\"></input></p>
	  <p><input type=\"submit\" name=\"Submit\" value=\"".$login."\"></input></p>
	  </form>";

}elseif(($_POST['password'] == $password)||(isset($_SESSION['password']))){

	if($url[1] == "logout"){
		
		session_destroy();
		header("Location: admin.php");
	
	}elseif($url[1] == "1"){

		
	}elseif($url[1] == "2"){			
		
		$sql = "SELECT id, email FROM ".$prefix."subscribers";
		$result = mysql_query($sql, $conn)or die(mysql_error());
		
		$recipients = array();
		while($newArray  = mysql_fetch_array($result)){
			array_push($recipients, $newArray['email']);
	
		}		
		
		$mail = new Swift(new Swift_SMTP_Connection($mailserver));
		
		$text = str_replace('/UserFiles','http://'.$_SERVER['HTTP_HOST'].'/UserFiles', $_POST['FCKeditor1']);
		
		if(!$mail->hasFailed()){

			$mail->loadPlugin(new Swift_Anti_Flood_Plugin(100, 30));
			//Make the script run until it's finished in the background
			set_time_limit(0); ignore_user_abort();			
			$mail->addPart($text, 'text/html');
			$mail->send($recipients, '"'.$yourname.'" <'.$youremail.'>', $_POST['subject']);
			$mail->close();
			$display_block = $sent.'.';
		}else{
			$display_block = "The mailer failed to connect. Errors: ".print_r($mailer->errors, 1).". Log: ".print_r($mailer->transactions, 1);
		}
		
	}elseif($url[1] == "3"){		
	
		$display_block = listsubscribers();
	
	
	}elseif($url[1] == "4"){
		
		$sql = "SELECT * 
				FROM ".$prefix."activation";
		$result = mysql_query($sql, $conn)or die(mysql_error());
		$num2 = mysql_num_rows($result);
				
		if(gettype($num2) == "NULL"){
			$num2 = 0;
		}		
		$display_block = $l_amnotactivated.": <b>".$num2."</b>";
		
		$timestamp = time() - 172800;
		
		$sql = "SELECT * 
				FROM ".$prefix."activation
				WHERE `timestamp` < ".$timestamp;
				
		$result = mysql_query($sql, $conn)or die(mysql_error());
		$num = mysql_num_rows($result);
		
		$display_block .= "<br/>".$l_amnotactivated." ".$l_48hours."<b>: ".$num."</b><br/>";
		
		$display_block .= "<br/><a href=\"admin.php?p=5\">".$l_removenotactivated.".</a>";
	
	
	}elseif($url[1] == "5"){
	//removebulk
		removebulk();

	
	}elseif($url[1] == "6"){
	
		$display_block .= remove();
	
	}else{				
		$_SESSION['password'] = 1;
		$display_block = "<b>".$loggedin."</b><br/>";
			
		$sql = "SELECT * 
				FROM ".$prefix."activation";
				
		$result = mysql_query($sql, $conn)or die(mysql_error());
		$num2 = mysql_num_rows($result);
				
		if(gettype($num2) == "NULL"){
			$num2 = 0;
		}		
		$display_block .= $l_amnotactivated.": <b>".$num2."</b>";
		
		$timestamp = time() - 172800;
		
		$sql = "SELECT * 
				FROM ".$prefix."activation
				WHERE `timestamp` < ".$timestamp;
				
		$result = mysql_query($sql, $conn)or die(mysql_error());
		$num = mysql_num_rows($result);
		
		$display_block .= "<br/>".$l_amnotactivated." ".$l_48hours."<b>: ".$num."</b>";
		
		
	
		$sql = "SELECT *
				FROM ".$prefix."subscribers";			
		$result = mysql_query($sql, $conn)or die(mysql_error());		
		$num = mysql_num_rows($result);	
		
		$display_block .= "<br/>".$l_amountsubscribed.":<b> ".$num."</b>";
	
	}		
		
}else{

		$display_block .=  $l_wrong.' '.$l_password;
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<title>Crisses Mailinglist</title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<link href="style.css" rel="stylesheet" type="text/css"></link></head><body>
		<div class="container">
		<div class="Table_01">
	<div class="header_">
		<img id="header" src="images/header.gif" width="830" height="51" alt="" />
		<div id="headline">
			<h1>' . $title .  '</h1>
		</div>
	</div>	<div class="background_">
	</div>';
		
			
if(isset($_SESSION['password'])){

	echo '<div class="menu_">
		<b>Menu</b><br/>
		<a href="admin.php"><img src="images/house.png" alt="" border="0" /> '.$l_home.'</a><br/>
		<a href="admin.php?p=1"><img src="images/email.png" alt="" border="0" /> '.$l_sendmail.'</a><br/>	
		<a href="admin.php?p=3"><img src="images/text_align_justify.png" alt="" border="0" /> '.$l_list.'</a><br />
		'#<a href=""><img src="images/help.png" alt="" border="0"> '.$l_help.'</a><br />
		.'<a href="admin.php?p=4"><img src="images/cancel.png" alt="" border="0" /> '.$l_notactivated.'</a><br />
		<a href="admin.php?p=logout"><img src="images/user.png" alt="" border="0" />'.$l_logout.'</a>
	   </div>';

}if(($url[1] == '1')&&(isset($_SESSION['password']))){
	echo '<div class="content_">
			<form action="admin.php?p=2" method="post"><b>
			'.$l_subject.':</b><br/><input type="text" size="50" maxlength="50" name="subject"></input><br/><br/>'.$l_firefoxproblem.'<br/><br/>	';
	
	$oFCKeditor->FileBrowserLanguage = 'php' ;      // asp | aspx | cfm | lasso | perl | php | py
	$oFCKeditor->QuickUploadLanguage = 'php' ;      // asp | aspx | cfm | lasso | php
#	$oFCKeditor->Height = '400';
	$oFCKeditor = new FCKeditor('FCKeditor1') ;
	$oFCKeditor->BasePath = 'FCKeditor/';
	$oFCKeditor->ToolbarSet = 'mailform';
	$oFCKeditor->Create() ;
	echo  '<br />
		<input type="submit" value="'.$l_submit.'"></input>
		</form></div> <div class="footer_">
		<img id="footer" src="images/footer.gif" width="830" height="6" alt="" />
	</div><div class="copyright_">&copy; 2006 <a href="http://code.google.com/p/crissesmailinglist/">Crisses Mailinglist/a> ' .  $xes_version . '</div>
</div></div>';
}if($url[1] != 1){

echo '	<div class="content_">'.$display_block.'</div>	<div class="footer_">
		<img id="footer" src="images/footer.gif" width="830" height="6" alt="" />
	</div><div class="copyright_">&copy; <a href="http://code.google.com/p/crissesmailinglist/">Crisses Mailinglist</a>   ' . $xes_version . '</div>
</div></div>';

}
echo "</body></html>";
?>

